
package cfar.distributed.map;

import cfar.actors.Node;
import cfar.ff.data.List;
import cfar.ff.fun.F1;
import cfar.ff.fun.F3;
import cfar.ff.fun.Seq;
import cfar.ff.interfaces.Sequence;



/**
 *
 * @author badi
 */
public class Map<S1,S2,A,B> implements F3< Sequence<S2,Node>, F1<A,B>, Sequence<S1,A>, Sequence<S1,B> > {


    public Sequence<S1, B> f( Sequence<S2,Node> avail_nodes
                            , F1<A, B>          f
                            , Sequence<S1, A>   seq         )
    {
        Sequence<S1,Integer> redundancies = (Sequence<S1, Integer>) seq.<Integer>empty();
        for(A a : seq)
            redundancies = redundancies.cons(1);
        return Seq.distRMap(redundancies, chooser, avail_nodes, f, seq);
    }

    F1<List<B>, B> chooser = new F1<List<B>, B>() {

        public B f(List<B> l) {
            return l.head();
        }
    };
}
